package com.kly.sc.api.application.controller.pay;

import com.kly.dto.ApplePayDto;
import com.kly.sc.api.application.helper.RequestLocalInfo;
import com.kly.sc.api.application.utils.Result;
import com.kly.service.pay.ApplePayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/applePay")
@Api(value = "/api/applePay", tags = "苹果支付")
public class ApplePayController {

    @Resource
    private ApplePayService applePayService;

    @PostMapping("/refundTrade")
    @ApiOperation(value = "苹果支付验证", notes = "苹果支付验证")
    public Result refundTrade(@RequestBody ApplePayDto applePayDto) {
        String userCode = RequestLocalInfo.getCurrentUser().getUserCode();
        ApplePayDto applePayDTO = new ApplePayDto();
        applePayDTO.setUserCode(userCode);
        applePayDTO.setTransactionReceipt(applePayDto.getTransactionReceipt());
        applePayDTO.setType(applePayDto.getType());
        applePayDTO.setTradeNo(applePayDto.getTradeNo());
        applePayDTO.setTransactionIdentifier(applePayDto.getTransactionIdentifier());
        int result = applePayService.notifyOfApplePay(applePayDTO);
        return Result.ok(result);
    }


    @GetMapping("/appleVip")
    @ApiOperation(value = "苹果判断是否是vip", notes = "苹果判断是否是vip")
    public Result appleVip() {
        String userCode = RequestLocalInfo.getCurrentUser().getUserCode();
        return Result.ok(applePayService.getAppleVipFlag(userCode));
    }

}
